package com.example.demo1.Demo2;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;

//@Controller//表示这个类是一个控制器类--MVC，用于接受前端请求，调用业务逻辑，响应数据给前端
//@ResponseBody
@RestController
@RequestMapping("/emp")
public class EmployeeController {
    //http://localhost:8080/emp/add.do?id=1&name=aa&age=20&salary=23.5&ah=a1&ah=b2&ah=c3
    @RequestMapping("add.do")
    public String add(Employee emp) {
        System.out.println("接收到前端请求");
        System.out.println(emp);
        return "EmployeeController-add";
    }
    //http://localhost:8080/emp/update.do?id=1&name=aa&age=20&salary=23.5&ah=a1&ah=b2&ah=c3
    @RequestMapping("update.do")
    public String update(@RequestParam("id") long id, String name, int age, double salary,String[] ah) {
        System.out.println("接收到前端请求");
        System.out.println(id);
        System.out.println(name);
        System.out.println(age);
        System.out.println(salary);
        System.out.println(Arrays.toString(ah));
        return "EmployeeController-update";
    }
}
